package com.example.pinkcat.activity.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.pinkcat.R;
import com.example.pinkcat.activity.Agreement;

public class PCA_recyleview_adapter extends RecyclerView.Adapter<PCA_recyleview_adapter.ViewHolder>{
    private final Context context;
    int pl_numbers;
    String agreementData;
    boolean privacyAgreement=false;

    //构造方法
    public PCA_recyleview_adapter(Context context, int pl_numbers,boolean privacyAgreement){
        this.context=context;
        this.pl_numbers=pl_numbers;
        this.privacyAgreement=privacyAgreement;
    }

    //内部内
    public static class ViewHolder extends RecyclerView.ViewHolder{
        TextView agreementTxt;

        //寻找声明布局控件
        public ViewHolder(View view) {
            super(view);
            agreementTxt=view.findViewById(R.id.agreement_txt_TextView);
        }
    }
    //创建获取 view  布局
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //获取item内容
        View view;
            view= LayoutInflater.from(context).inflate(R.layout.list_agreemment_txt,parent,false);
        return new ViewHolder(view);
    }

    //绑定数据
    @SuppressLint({"CheckResult", "SetTextI18n"})
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        if (privacyAgreement)
            holder.agreementTxt.setText(Agreement.privacy);
        else
            holder.agreementTxt.setText(Agreement.user);
    }

    @Override
    public int getItemCount() {
        return pl_numbers;
    }

    //添加数据
    public void flashData(String data){
        this.agreementData=data;
        notifyDataSetChanged();
    }
}
